<document type="freeswitch/xml">
  <section name="dialplan" description="RE Dial Plan For FreeSwitch">
	<context name="default">
		<extension name="unloop">
	      <condition field="${unroll_loops}" expression="^true$"/>
	      <condition field="${sip_looped_call}" expression="^true$">
			<action application="deflect" data="${destination_number}"/>
	      </condition>
	    </extension>
	    
	    <#if routerList??>
	    <#list routerList as router>
	    <extension name="${router.name!''}">
	      <condition field="${router.field!''}" expression="${router.regex!''}" break="${router.falsebreak!'never'}">
			${(router.routercontent!'')?no_esc}
	      </condition>
	    </extension>
	    </#list>
	    </#if>
	    
	    <!-- a sample IVR  -->
	    <extension name="ivr_demo">
	      <condition field="destination_number" expression="5050">
			<action application="set" data="language=zh"/>
	        <action application="answer"/>
	        <action application="sleep" data="2000"/>
			<action application="set" data="sound_prefix=${r'$${sounds_dir}'}/en/us/callie/zh"/>
			<action application="ivr" data="demo_ivr"/>
	      </condition>
	    </extension>
	
		<extension name="callcenter">
			<condition field="destination_number" expression="3000">			
			  <action application="limit" data="hash inbound ${r'${destination_number}'} 3/1 !NORMAL_CIRCUIT_CONGESTION"/>
			  <!-- play a message before entering the queue. -->
			  <action application="playback" data="ivr-welcome.wav"/>
			  <!-- hangup after successful bridge to agent -->
			  <action application="set" data="hangup_after_bridge=true"/>
			  <!-- queue caller -->
			  <action application="answer"/>
			  <action application="callcenter" data="ukefu"/>
			  <!-- if no agent was reached and using max-wait-time - send to general voicemail -->
			  <action application="playback" data="ivr-welcome.wav"/>
			  
			  <action application="set" data="skip_greeting=true"/>
			  <action application="set" data="skip_instructions=true"/>
			  <action application="voicemail" data="default voicemail 2001"/>
			  <action application="hangup"/>
			</condition>
	    </extension>
	    
		<extension name="Local_Extension">
	      <condition field="destination_number" expression="^(10[0-9][0-9])$">
			<action application="export" data="dialed_extension=$1"/>
			<!-- bind_meta_app can have these args <key> [a|b|ab] [a|b|o|s] <app> -->
			<action application="bind_meta_app" data="1 b s execute_extension::dx XML features"/>
			<action application="bind_meta_app" data="2 b s record_session::${r'$${recordings_dir}/${caller_id_number}.${strftime(%Y-%m-%d-%H-%M-%S)}'}.wav"/>
			<action application="bind_meta_app" data="3 b s execute_extension::cf XML features"/>
			<action application="bind_meta_app" data="4 b s execute_extension::att_xfer XML features"/>
			<action application="set" data="ringback=${r'${us-ring}'}"/>
			<action application="set" data="transfer_ringback=${r'$${hold_music}'}"/>
			<action application="set" data="call_timeout=30"/>
			<!-- <action application="set" data="sip_exclude_contact=${r'${network_addr}'}"/> -->
			<action application="set" data="hangup_after_bridge=true"/>
			<!--<action application="set" data="continue_on_fail=NORMAL_TEMPORARY_FAILURE,USER_BUSY,NO_ANSWER,TIMEOUT,NO_ROUTE_DESTINATION"/> -->
			<action application="set" data="continue_on_fail=true"/>
			<action application="hash" data="insert/${r'${domain_name}-call_return/${dialed_extension}/${caller_id_number}'}"/>
			<action application="hash" data="insert/${r'${domain_name}-last_dial_ext/${dialed_extension}/${uuid}'}"/>
			<action application="set" data="called_party_callgroup=${r'${user_data(${dialed_extension}@${domain_name} var callgroup)}'}"/>
			<action application="hash" data="insert/${r'${domain_name}-last_dial_ext/${called_party_callgroup}/${uuid}'}"/>
			<action application="hash" data="insert/${r'${domain_name}-last_dial_ext/global/${uuid}'}"/>
			<!--<action application="export" data="nolocal:rtp_secure_media=${r'${user_data(${dialed_extension}@${domain_name} var rtp_secure_media)}'}"/>-->
			<action application="hash" data="insert/${r'${domain_name}-last_dial/${called_party_callgroup}/${uuid}'}"/>
			<action application="bridge" data="user/${r'${dialed_extension}@${domain_name}'}"/>
			<action application="answer"/>
			<action application="sleep" data="1000"/>
			<action application="bridge" data="loopback/app=voicemail:default ${r'${domain_name} ${dialed_extension}'}"/>
	      </condition>
	    </extension>
	
	</context>    
  </section>
</document>
